{extend name="$base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/member_list.css" />
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
#account_update .modal-header ul li{
    display: inline-block;
    width: 100px;
    text-align: center;
}
#account_update .modal-header ul li:hover{
	cursor:pointer;
}
.modal-header .close {
    position: absolute;
    right: 20px;
}
.account_active{
	border-bottom: 2px solid #00A0DE;
}
.table-class tr td:nth-child(4){
	color: #F79136;
	text-align: right;
}
.table-class tr td:nth-child(5){
	color: #00A0DE;
	text-align: right;	
}
.edit-group{border-bottom: 1px solid #ebebeb;margin-bottom:10px;    padding-bottom: 13px;}
.edit-group label{font-weight:normal;}
.edit-group-title{height:15px;line-height:15px;width:140px;margin-top:3px;margin-bottom:3px;color:#00A0DE;}
.edit-group-button{border: 1px solid #bbb;height: 26px;line-height: 24px;padding: 0 5px;}
.clear {
	clear: both;
}
.label-bg {
    height: 20px;
    font-size: 12px;
    text-align: center;
    background-color: #FF6600;
    color: #fff;
    border-radius: 1px;
    padding: 1px 3px;
    margin-right: 3px;
}
</style>
{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th style="text-align: left;width: 20%;">
			<button class="btn-common" onclick="add_user()" >添加会员</button>
		</th>
		<th style="width:50%;" class="default-condition"> 
			<input type="text" id ='search_text' placeholder="手机号/邮箱/会员昵称" class="input-common middle" />
			<!-- 更多搜索按钮 -->
			<button onclick="searchData()" value="搜索" class="btn-common" >搜索</button>
			<button onclick="openSeniorSearch('.default-condition')" value="搜索" class="btn-common">高级搜索</button>
			<button onclick="dataExcel()" value="导出数据" class="btn-common"  >导出数据</button>
		</th>
	</tr>
</table>

<!-- 高级搜索 -->
<div class="nui-condition">
	<div class="c-item-column">
		<label>搜索内容：</label>
		<input type="text" id ='search_text' placeholder="手机号/邮箱/会员昵称" class="input-common middle" />
	</div>
	<div class="c-item-column">
		<label>会员等级：</label>
		<select id="level_name" class="select-common middle">
			<option value ="">请选择会员等级</option>
			{volist name="level_list['data']" id="vo"}
			<option value ="{$vo.level_id}">{$vo.level_name}</option>
			{/volist}
		</select>
	</div>
	
<!-- 	<div class="c-item-column"> -->
<!-- 		<label for="">会员标签：</label> -->
<!-- 		<select id="label_name" class="select-common middle"> -->
<!-- 			<option value ="">请选择会员标签</option> -->
<!-- 			{foreach name="label_list['data']" item="vo"} -->
<!-- 			<option value="{$vo.id}">{$vo.label_name}</option> -->
<!-- 			{/foreach} -->
<!-- 		</select> -->
<!-- 	</div> -->
	<div class="c-item-column">
		<label>会员标签：</label>
		<input type="text" placeholder="请选择会员标签" id="selectMemberLabel"  onfocus="selectMemberLabel();" is_show="false" data-html="true" class="input-common middle" title="<h6 class='edit-group-title'>选择会员标签</h6>" data-container="body" data-placement="bottom"  data-trigger="manual" data-content="<div class='edit-group' style='max-width:auto;'>
			{foreach label_list['data'] as $vo}
					<p>
					<label class='checkbox-inline' style='display:inline-block;width: 100%;'>
					<input type='checkbox' value='{$vo.id}' onchange='clickMemberLabel(this);'><span>{$vo.label_name}</span>&nbsp;&nbsp;&nbsp;
					</label>
					<div class='clear'></div>
				{/foreach}
			</div></div>
			<button class='btn-common btn-small' onclick='confirm();'>确认</button>
			<button class='btn btn-small' onclick='hideGroup()'>取消</button>
			">
	</div>
	
	<br />

	<div class="c-item-column">
		<label>注册时间：</label>
		<input type="text" id="startDate" class="input-common middle" placeholder="请选择开始日期" onclick="WdatePicker()" />
		&nbsp;-&nbsp;
		<input type="text" id="endDate" placeholder="请选择结束日期" class="input-common middle" onclick="WdatePicker()" />
	</div>
	<br />
	<div class="c-operation">
		<button onclick="searchData()"  value="搜索" class="btn-common" >搜索</button>
		<button onclick="dataExcel()"  value="搜索" class="btn-common-white" >导出</button>
		<a href="javascript:clearCondition();">清空筛选条件</a>
	</div>
	<a href="javascript:retractSeniorSearch();" class="retract">收起↑</a>
</div>
<table class="table-class">
	<colgroup>
	<col style="width: 2%;">
	<col style="width: 21%;">
	<col style="width: 7%;">
	<col style="width: 10%;">
	<col style="width: 10%;">
	<col style="width: 20%;">
	<col style="width: 6%;">
	<col style="width: 20%;">
	</colgroup>
	<thead>
		<tr align="center">
			<th><!-- <i class="checkbox-common"><input type="checkbox" ></i> --></th>
			<th style="text-align:left;">会员</th>
			<th style="text-align:left;">会员等级</th>
			<th style="text-align:right;">积分</th>
			<th style="text-align:right;">账户余额</th>
			<th>注册&登录</th>
			<th>状态</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody id="productTbody"></tbody>
</table>

<!-- 账户调整 -->
<div class="modal fade hide" id="account_update" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<ul class="account_ul">
					<li class="account_active">
						<h3>调整积分</h3>
					</li>
					<li>
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h3>调整余额</h3>
					</li>
				</ul>
			</div>
			<div class="account-point">
				<div class="modal-body">
					<div class="modal-infp-style">
						<table>
							<tr>
								<td>当前积分</td>
								<td colspan='3' id="current_point" class="input-common"></td>
							</tr>
							<tr>
								<td>调整积分</td>
								<td colspan='3'>
									<input type="number" id="point" class="input-common harf">
									<em class="unit">分</em>
									<p class="hint">输入负数表示为减少</p>
								</td>
							</tr>
							<tr>
								<td>备注</td>
								<td colspan='3'><textarea id="remark_point" class="textarea-common"></textarea></td>
							</tr>
						</table>
						
					</div>
				</div>
				<div class="modal-footer">
					<input type="hidden" id="point_id" />
					<button class="btn-common btn-big" onclick="addAccount(1)">保存</button>
					<button class="btn-common-cancle btn-big" data-dismiss="modal">关闭</button>
				</div>
			</div>
			
			<div class="account-balance"  style="display: none;">
				<div class="modal-body">
					<div class="modal-infp-style">
						<table>
							<tr>
								<td>当前余额</td>
								<td colspan='3' id="current_balance" class="input-common" ></td>
							</tr>
							<tr>
								<td>调整金额</td>
								<td colspan='3'>
									<input type="number" id="balance" class="input-common harf" /><em class="unit">元</em>
									<p class="hint">输入负数表示为减少</p>
								</td>
							</tr>
							<tr>
								<td>备注</td>
								<td colspan='3'><textarea id="remark_balance" class="textarea-common"></textarea></td>
							</tr>
						</table>
					</div>
				</div>
				<div class="modal-footer">
					<input type="hidden" id="balance_id" />
					<button class="btn-common btn-big" onclick="addAccount(2)">保存</button>
					<button class="btn-common-cancle btn-big" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- 添加会员 -->
<div class="modal fade hide" id="add_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>添加会员</h3>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table class="modal-tab">
						<tr>
							<td style="width:20%;"><span class="required">*</span>用户名</td>
							<td colspan='3'>
								<input type="text" id="username" class="input-common" />
								<span id="username_verify"></span>
								<input type="hidden" value="不存在" id="isset_username" class="input-common" />
							</td>
						</tr>
						<tr>
							<td><span class="required">*</span>登录密码</td>
							<td colspan='3'><input type="password" id="password" class="input-common"></td>
						</tr>
						<tr>
							<td style="width:22%;"><span class="required">*</span>昵称</td>
							<td colspan='3'>
								<input type="text" id="nickname" class="input-common" />
							</td>
						</tr>
						<tr>
							<td>会员等级</td>
							<td colspan='3'>
								{if $level_list['data']}
								<select id="member_level" class="select-common">
									{foreach name="level_list['data']" item="vo"}
									<option value="{$vo.level_id}">{$vo.level_name}</option>
									{/foreach}
								</select>
								{else/}
								<span>暂无会员等级</span>
								{/if}
							</td>
						</tr>
						<tr>
							<td>会员标签</td>
							<td colspan='3'>
								{if $label_list['data']}
								<select id="member_label" class="select-common">
									{foreach name="label_list['data']" item="vo"}
									<option value="{$vo.id}">{$vo.label_name}</option>
									{/foreach}
								</select>
								{else/}
								<span>暂无会员标签</span>
								{/if}
							</td>
						</tr>
						<tr>
							<td>手机号码</td>
							<td colspan='3'><input type="text" id="telephone" class="input-common"/><span id="telephone_verify"></span></td>
						</tr>
						<tr>
							<td>邮箱地址</td>
							<td colspan='3'><input type="text" id="member_email" class="input-common" /><span id="member_email_verify"></span></td>
						</tr>
						<tr>
							<td>性别</td>
							<td>
							<label class="radio inline normal"><i class="radio-common selected"><input type="radio" checked="checked" name="sex" value="1"/></i>
							<span>男</span></label>
							<label class="radio inline normal"><i class="radio-common"><input name="sex" type="radio" value="2"/></i>
							<span>女</span></label>
							<label class="radio inline normal"><i class="radio-common"><input name="sex" type="radio" value="0"/></i>
							<span>保密</span></label>
							</td>
						</tr>
						<tr>
							<td>账户状态</td>
							<td>
							<label class="radio inline normal"><i class="radio-common selected"><input type="radio" checked="checked" name="status" value="1"/></i>
							<span>正常</span></label>
							<label class="radio inline normal"><i class="radio-common"><input name="status" type="radio" value="0"/></i>
							<span>锁定</span></label>
							</td>
						</tr>
					</table>
				</div>
			</div>
			
			<div class="modal-footer">
				<button class="btn-common btn-big" onclick="addUser()">保存</button>
				<button class="btn-common-cancle btn-big" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
	
</div>

<input type="hidden" id="modify_uid"/>
<!-- 修改会员 -->
<div class="modal fade hide" id="modify_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog" >
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3 class="modal-title">编辑会员</h3>
			</div>
			<div class="modal-body" style="min-height: 360px;">
				<div class="modal-infp-style">
					<table class="modal-tab">
						<tr style="height: 32px;">
							<td style="width:20%"><span class="required">*</span>用户名</td>
							<td colspan='3'>
								<input type="text" id="modify_username" class="input-common" />
								<span id="modify_username_verify"></span>
								<input type="hidden" value="不存在" id="modify_isset_username"/>
							</td>
						</tr>
						<tr>
							<td style="width:20%">昵称</td>
							<td colspan='3'><input type="text" id="modify_nickname" class="input-common"/></td>
						</tr>
						<tr>
							<td>会员等级</td>
							<td colspan='3' style="padding-bottom: 0;">
								<p>
									{if $level_list['data']}
									<select id="modify_member_level" class="select-common">
										{foreach name="level_list['data']" item="vo"}
										<option value="{$vo.level_id}">{$vo.level_name}</option>
										{/foreach}
									</select>
									{else/}
									<span>暂无会员等级</span>
									{/if}
								</p>
							</td>
						</tr>
						<tr>
							<td>会员标签</td>
							<td colspan='3'>
								{if $label_list['data']}
								<select id="modify_member_label" class="select-common">
									{foreach name="label_list['data']" item="vo"}
									<option value="{$vo.id}">{$vo.label_name}</option>
									{/foreach}
								</select>
								{else/}
								<span>暂无会员标签</span>
								{/if}
							</td>
						</tr>
						<tr>
							<td>手机号码</td>
							<td colspan='3'><input type="text" id="modify_telephone" value="" class="input-common"/><span id="modify_telephone_verify"></span></td>
						</tr>
						<tr>
							<td>邮箱地址</td>
							<td colspan='3'><input type="text" id="modify_member_email" class="input-common"/><span id="modify_member_email_verify"></span></td>
						</tr>
				
						<tr>
							<td>性别</td>
							<td id="sex">
							<label class="radio inline normal"><i class="radio-common"><input type="radio" checked="checked" name="sex" value="1"/></i>
							<span>男</span></label>
							<label class="radio inline normal"><i class="radio-common"><input name="sex" type="radio" value="2"/></i>
							<span>女</span></label>
							<label class="radio inline normal"><i class="radio-common"><input name="sex" type="radio" value="0"/></i>
							<span>保密</span></label>
							</td>
						</tr>
						<tr>
							<td>账户状态</td>
							<td  id="status">
							<label  class="radio inline normal"><i class="radio-common"><input type="radio" checked="checked" name="status" value="1"/></i>
							<span>正常</span></label>
							<label  class="radio inline normal"><i class="radio-common"><input name="status" type="radio" value="0"/></i>
							<span>锁定</span></label>
							</td>
						</tr>
					</table>
				</div>
			</div>
			
			<div class="modal-footer">
				<input type="hidden" id="modify_username_hidden" />
				<input type="hidden" name="" id="hidden_old_username" value="">
				<button class="btn-common btn-big" onclick="modifyUser()" id="butSubmit"  >保存</button>
				<button class="btn-common-cancle btn-big" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
	
</div>

<!-- 修改会员密码 -->
<div class="modal fade hide" id="modify_password" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>重置密码</h3>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table class="modal-tab">
						<tr>
							<td style="width:20%">密码</td>
							<td colspan='3'><input type="text" id="modify_passwords" class="input-common"/></td>
						</tr>
					</table>
				</div>
			</div>
			
			<div class="modal-footer">
				<button class="btn-common btn-big" onclick="modifypassword()">保存</button>
				<button class="btn-common-cancle btn-big" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
	
</div>
<!-- 修改标签名称 -->
<div class="modal fade hide" id="modify_tab" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">修改标签</h4>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table class="modal-tab">
						<tr>
							<td style="width:20%">标签名称</td>
							<td colspan='3' class="c-item-column" style="position: relative;">
								<input type="text" placeholder="请选择会员标签" id="addSelectMemberLabel"  onfocus="addSelectMemberLabel();" is_show="false" data-html="true" class="input-common middle" title="<h6 class='edit-group-title'>选择会员标签</h6>" data-container="body" data-placement="bottom"  data-trigger="manual" data-content="<div class='edit-group' style='max-width:auto;'>
			{foreach label_list['data'] as $vo}
					<p>
					<label class='checkbox-inline' style='display:inline-block;width: 100%;'>
					<input type='checkbox' value='{$vo.id}' onchange='addclickMemberLabel(this);'><span>{$vo.label_name}</span>&nbsp;&nbsp;&nbsp;
					</label>
					<div class='clear'></div>
				{/foreach}
			</div></div>
			<button class='btn-common btn-small' onclick='confirm();'>确认</button>
			<button class='btn btn-small' onclick='hideGroup()'>取消</button>
			">
							</td>
						</tr>
					</table>
				</div>
			</div>
			
			<div class="modal-footer">
				<button class="btn btn-primary" onclick="saveMemberLabel()">保存</button>
				<button class="btn" onclick="closeMemberLabel()">关闭</button>
			</div>
		</div>
	</div>
</div>

<!--账户详情-->
<div class="modal fade hide" id="member_info" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>账户详情</h3>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table class="modal-tab">
						<tr>
							<td>用户名</td>
							<td>admin</td>
						</tr>
						<tr>
							<td>昵称</td>
							<td>admin</td>
						</tr>
						<tr>
							<td>手机号</td>
							<td>15</td>
						</tr>
						<tr>
							<td>邮箱</td>
							<td>admin</td>
						</tr>
						<tr>
							<td>会员标签</td>
							<td>admin</td>
						</tr>
						<tr>
							<td>会员等级</td>
							<td>admin</td>
						</tr>
						<tr>
							<td>QQ号</td>
							<td>admin</td>
						</tr>
						<tr>
							<td>账户状态</td>
							<td>a</td>
						</tr>
						<tr>
							<td>性别</td>
							<td>a</td>
						</tr>
						<tr>
							<td>注册时间</td>
							<td>a</td>
						</tr>
						<tr>
							<td>近期登录时间</td>
							<td>a</td>
						</tr>
					</table>
				</div>
			</div>
			
			<div class="modal-footer">
				<button class="btn-common-cancle btn-big" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>

</div>
<input type="hidden" id="selectMemberLabelId">
<input type="hidden" id="addSelectMemberLabelId">
<input type="hidden" id="modify_userid" />
{/block}
{block name="script"}
<script type="text/javascript">
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	var levelid = $("#level_name").val();
	var label_id = $("#selectMemberLabelId").val();
	var start_date = $("#startDate").val();
	var end_date = $("#endDate").val();
	var status = $("#status_search").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/member/memberlist')}",
		data : {
			"page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text,"levelid":levelid, 
			"start_date" : start_date, "end_date" : end_date, "status" : status, "label_id" :label_id
		},
		success : function(data) {
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					html += '<tr align="center">';
					html += '<td><!--<i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data["data"][i]["uid"]+'"></i>--></td>';
					html += '<td align="left" class="member-basics">';
					if(data["data"][i]["user_headimg"] ==""){
						html += '<img src="{:__IMG($default_headimg)}" class="head-portrait"/>';
					}else{
						html += '<img src="'+__IMG(data["data"][i]["user_headimg"])+'" class="head-portrait"/>';
					}
					html += '<div style="float:left;" class="member-div">';
                  	var label_name_str = '';
					if(data['data'][i]['label_arr'] == ''){
						html += '<label style="float:none;width:100%;"';
					}else{
						html += '<label style="float:none;width:100%;margin-top:3px;"';
					}
					if(data["data"][i]["nick_name"] == '' || data["data"][i]["nick_name"] == null){
						html += '<a href="'+__URL('ADMIN_MAIN/member/memberdetail?member_id='+ data['data'][i]['uid'])+'" style="margin-left:0px;">匿名用户</a>';
					}else{
						html += '<a href="'+__URL('ADMIN_MAIN/member/memberdetail?member_id='+ data['data'][i]['uid'])+'" style="margin-left:0px;">'+data["data"][i]["nick_name"]+'</a>';
					}
					if(data['data'][i]['label_arr'] != '')
					html += '<br>';
					$.each(data['data'][i]['label_arr'], function(obj, e) {
						label_name_str += e.label_name+';';
						html += '<span class="label-bg">'+e.label_name+'</span>';
					});
					
					html += '</label>';
					
					html += '</div>';
					html += '<div class="msg_member">';
						html += '<p><span>会员ID：</span>'+data["data"][i]["uid"]+'</p>';
						html += '<p><span>会员账号：</span>'+(data["data"][i]["user_name"] == '' ? '--' : data["data"][i]["user_name"])+'</p>';
						html += '<p><span>会员昵称：</span>'+(data["data"][i]["nick_name"] == '' ? '匿名用户' : data["data"][i]["nick_name"])+'</p>';
						
						html += '<p><span>手机号码：</span>'+(data["data"][i]["user_tel"] == '' ? '--' : data["data"][i]["user_tel"])+'</p>';
						html += '<p><span>会员邮箱：</span>'+(data["data"][i]["user_email"] == '' ? '--' : data["data"][i]["user_email"])+'</p>';
					html += '<span class="transform-left"></span></div></td>';
					if(data["data"][i]["level_name"]==null || data["data"][i]["level_name"]==undefined){
						html += '<td >--</td>';
					}else{
						html += '<td style="text-align:left;">' + data["data"][i]["level_name"] + '</td>';
					}
					html += '<td style="text-align:right;">' + data["data"][i]["point"] + '</td>';
					html += '<td style="text-align:right;">'+'¥'+ data["data"][i]["balance"] +'</td>';
					html += '<td>' +'注册时间 : '+ timeStampTurnTime(data["data"][i]["reg_time"]) +'<br>'+'最后登录 : '+ timeStampTurnTime(data["data"][i]["current_login_time"])+'</td>';
					html += data["data"][i]["user_status"] == 0 ? '<td style="color:red;">锁定</td>' : '<td style="color:green;">正常</td>';
					html += '<td>';
					// html += '<a href="javascript:accountDetail(' + data['data'][i]['uid'] + ');">账户详情</a><br/>';
					
					html += '<a href="'+__URL('ADMIN_MAIN/member/memberdetail?member_id='+ data['data'][i]['uid'])+'">详情</a>&nbsp;&nbsp;';
					if(data["data"][i]["is_system"] != 1){
						if(data["data"][i]["user_status"] == 0){
							html += '<a onclick="unlockuser('+ data["data"][i]["uid"]+')">解锁&nbsp;&nbsp;</a>';
						}else{
							html += '<a onclick="lockuser('+ data["data"][i]["uid"]+')">锁定&nbsp;&nbsp;</a>';
						}
						// html += '<a onclick="modify_password('+ data["data"][i]["uid"]+')">重置密码</a><br/>';
						// html += '<a href="'+__URL('ADMIN_MAIN/member/newpath?member_id='+ data['data'][i]['uid'])+'">查看足迹</a>';
						html += '<a onclick="modify_user('+ data["data"][i]["uid"]+')">修改&nbsp;&nbsp;</a><br/>';
						//html += '<a onclick="delete_user('+ data["data"][i]["uid"]+')">删除</a><br/>';
						
					}
					html += '<a onclick="modify_password('+ data["data"][i]["uid"]+')">重置密码</a>';
					html += '<a onclick="account_update('+ data["data"][i]["uid"]+','+ data["data"][i]["point"] +','+data["data"][i]["balance"]+')">账户调整</a>&nbsp;&nbsp;';
					html += '<a onclick="modify_tab('+ data["data"][i]["uid"]+', \''+label_name_str+'\', \''+data['data'][i]['member_label']+'\')">修改标签</a>';
					html += '</td>';
					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

function searchData(){
	$(".more-search-container").slideUp();
	LoadingInfo(1);
}
	
//锁定会员
function lockuser(uid){
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/member/memberlock')}",
		data : { "id" : uid },
		success : function(data) {
			if (data["code"] > 0) {
				LoadingInfo(getCurrentIndex(uid,'#productTbody'));
				showTip(data['message'],'success');
			}else{
				showTip(data['message'],'error');
			}
		}
	});
}

//解锁会员
function unlockuser(uid){
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/member/memberunlock')}",
		data : { "id" : uid },
		success : function(data) {
			if (data["code"] > 0) {
				LoadingInfo(getCurrentIndex(uid,'#productTbody'));
				showTip(data['message'],'success');
			}else{
				showTip(data['message'],'error');
			}
		}
	});
}
	
//添加会员弹出
function add_user(){
	$("#add_user").modal("show");
}

//修改选项标签
function modify_tab(uid, label_name_str, id){
	$("#modify_tab").modal("show");
	$("#modify_uid").val(uid);
	$('#addSelectMemberLabel').val(label_name_str);
	$('#addSelectMemberLabelId').val(id);
}

//积分充值
function recharge_point(uid,point){
	$("#recharge_point").modal("show");
	$("#point_id").val(uid);
	$("#current_point").text(point);
}
//余额充值
function recharge_balance(uid,balance){
	$("#recharge_balance").modal("show");
	$("#balance_id").val(uid);
	$("#current_balance").text(balance);
}
// 账户调整
function account_update(uid,point,balance){
	$("#point_id,#balance_id").val(uid);
	$("#current_point").text(point);
	$("#current_balance").text(balance);
	$("#account_update").modal("show");
}
$(".account_ul li").each(function(i){
	$(".account_ul li").eq(i).click(function(){
		$(".account_ul li").eq(i).addClass('account_active').siblings(".account_ul li").removeClass('account_active');
		if(i==0){
			// 积分
			$(".account-point").show();
			$(".account-balance").hide();
		}else if(i==1){
			// 余额
			$(".account-point").hide();
			$(".account-balance").show();
		}
	})
	
});

//充值
function addAccount(type){
	if(type == 1){
		var id = $("#point_id").val();
		var num = $("#point").val();
		var current_point = $("#current_point").text();
		var point = (parseInt(current_point) + parseInt(num));
		if(num == ''){
			showTip('积分不能为空','warning');
			return false;
		}
		var text = $("#remark_point").val();
		if(parseInt(point) < 0){
			showTip('积分不能为负数','warning');
			return false;
		}
	}else{
		var id = $("#balance_id").val();
		var num = $("#balance").val();
		var current_balance = $("#current_balance").text();
		var balance = (parseInt(current_balance) + parseInt(num));
		if(num == ''){
			showTip('余额不能为空','warning');
			return false;
		}
		var text = $("#remark_balance").val();
		if(parseInt(balance) < 0){
			showTip('余额不能为负数','warning');
			return false;
		}
	}
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/member/addmemberaccount')}",
		data : {
			"id" : id,
			"type" : type,
			"num" : num,
			"text" : text
		},
		success : function(data) {
			if (data["code"] > 0) {
				LoadingInfo(getCurrentIndex(id,'#productTbody'));
				showTip(data['message'],'success');
				$("#account_update").modal("hide");
			}else{
				showTip(data['message'],'error');
			}
		}
	});
}

function checkUserName(username){
	var flag = true;
	$.ajax({
		type: "GET",
		url: "{:__URL('ADMIN_MAIN/member/check_username')}",
		async : false,
		data: {"username":username},
		success: function(data){
			if(data){
				flag = false;
				$("#username").css("border","1px solid red");
				$("#username_verify").css("color","red").text("用户名已存在");
				$("#isset_username").attr("value","存在");
			}
		} 
	});
	return flag;
}

function checkMobile(mobile){
	var flag = false;
	$.ajax({
		type: "post",
		url: "{:__URL('ADMIN_MAIN/member/checkUserInfoIsExist')}",
		async : false,
		data: {"info":mobile,"type":"mobile"},
		success: function(data){
			if(data){
				flag = true;
			}
		} 
	});
	return flag;
}

function checkEmail(email){
	var flag = false;
	$.ajax({
		type: "post",
		url: "{:__URL('ADMIN_MAIN/member/checkUserInfoIsExist')}",
		async : false,
		data: {"info":email,"type":"email"},
		success: function(data){
			if(data){
				flag = true;
			}
		} 
	});
	return flag;
}

//添加会员
function addUser(){
	var username = $("#username").val();
	var nickname = $("#nickname").val();
	var password = $("#password").val();
	var level_name = $("#member_level").val();
	var member_label = $("#member_label").val();
	var tel = $("#telephone").val();
	var email = $("#member_email").val();
	var sex = $("input[name='sex']:checked").val();
	var status = $("input[name='status']:checked").val();
	
	if (username == '') {
		showTip('用户名不能为空','warning');
		return;
	}
	if(!checkUserName(username)){
		showTip('用户名已存在','warning');
		return;
	}

	if (password == null || password.length < 6) {
		showTip('密码必须不小于6位！','warning');
		return;
	}
	if (nickname == '') {
		showTip('昵称不能为空','warning');
		return;
	}
	if(tel.length > 0){
		if(!(/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(tel))){ 
			showTip("手机号码有误，请重填",'warning');
			return; 
		}
		if(checkMobile(tel)){
			showTip('该手机号码已存在','warning');
			return; 
		}
	}
	if(email.length > 0){
		if(!(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(email))){ 
			showTip('邮箱错误,请重填','warning');
			return; 
		}
		if(checkEmail(email)){
			showTip('该邮箱已存在','warning');
			return; 
		}
	}
	$.ajax({
		type : "post",
		url : __URL("ADMIN_MAIN/member/addmember"),
		data : {
			'username' : username,
			'nickname' :nickname,
			'password' : password,
			'level_name' : level_name,
			'member_label' : member_label,
			'tel' : tel,
			'email' : email,
			'sex' : sex,
			'status' : status
		},
		success : function(data) {
			if (data['code'] > 0) {
				showTip(data['message'],'success');
				$("#add_user").modal("hide");
				LoadingInfo(getCurrentIndex(1,'#productTbody'));
			} else {
				showTip(data['message'],'error');
				flag = false;
			}
		}
	});
}
//修改会员弹出
function modify_user(uid){
	var id = parseInt(uid);
	$("#modify_user").modal("show");
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/member/getmemberdetail')}",
		data : { 'uid':id, },
		success : function(data) {
			//alert(JSON.stringify(data['user_name']));
			$("#modify_uid").val(data.uid);
			if(data['user_name']!=''){
				$("#modify_username,#hidden_old_username").val(data.user_name);
				$("#modify_username").attr('disabled',true);
			}else{
				$("#hidden_old_username").val("");
				$("#modify_username").attr('disabled',false).val("");
			}
			
			$("#modify_nickname").val(data.nick_name);
			//$("#modify_password").val(data.user_password);
			$("#modify_username_hidden").val(data.user_name);
			$("#modify_telephone").attr("old-value", data.user_tel).val(data.user_tel);
			$("#modify_member_email").attr("old-value", data.user_email).val(data.user_email);

			//$("#modify_member_level").find("option[value="+data.member.member_level+"]").attr("selected",true);
			$("#modify_member_level").val(data.member.member_level).selectric();
			$("#modify_member_label").val(data.member.member_label).selectric();
			$("#sex").find("input[value="+data.sex+"]").attr("checked",true);
			$("#status").find("input[value="+data.user_status+"]").attr("checked",true);
			
			$("#modify_user").find("input[name='status']").parent().removeClass("selected");
			$("#modify_user").find("input[name='sex']").parent().removeClass("selected");
			$("#sex").find("input[value="+data.sex+"]").parent().addClass("selected");
			$("#status").find("input[value="+data.user_status+"]").parent().addClass("selected");
		}
	});
}

//重置密码弹出
function modify_password(uid){
	$("#modify_password").modal("show");
	$("#modify_userid").val(uid);
}

//修改密码提交
function modifypassword(){
	var uid = $("#modify_userid").val();
	var password = $("#modify_passwords").val(); 
	if (password == null || password.length < 6) {
		showTip('密码必须不小于6位！','warning');
		return false;
	}
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/member/updatememberpassword')}",
		data : {
			'uid':uid,
			'user_password' :password
		},
		success : function(data) {
			if (data['code'] > 0) {
				showTip('修改成功','success');
				LoadingInfo(getCurrentIndex(uid,'#productTbody'));
				$("#modify_password").modal("hide");
			} else {
				showTip('修改失败','error');
				flag = false;
			}
		}
	});
}

function delete_user(uid){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$.ajax({
					type : "post",
					url : "{:__URL('ADMIN_MAIN/member/deletemember')}",
					data : { "uid" : uid.toString() },
					dataType : "json",
					success : function(data) {
						if(data["code"] > 0 ){
							LoadingInfo(getCurrentIndex(uid.toString(),'#productTbody'));
							showTip(data["message"],'success');
							$("#chek_all").prop("checked", false);
						}else{
							showTip(data["message"],'error');
						}
					}
				});
				$(this).dialog('close');
			},
			"取消,#f5f5f5,#666": function() {
				$(this).dialog('close');
			},
		},
		contentText:"删除会员同时会删除会员相关账户信息，确定要删除吗？",
	});
}

//修改会员
function modifyUser(){
	var uid = $("#modify_uid").val();
	var nickname = $("#modify_nickname").val();
	var username = $("#modify_username").val();

	var tel = $("#modify_telephone").val();
	var old_tel = $("#modify_telephone").attr("old-value");

	var email = $("#modify_member_email").val();
	var old_email = $("#modify_member_email").attr("old-value");

	var level_name = $("#modify_member_level").val();
	var member_label = $("#modify_member_label").val();
	var sex = $("input[name='sex']:checked").val();
	var status = $("input[name='status']:checked").val();
	
	if(nickname == ""){
		showTip("昵称不能为空","warning");
		$("#modify_nickname").focus();
		return;
	}
	
	if (username == '') {
		showTip('用户名不能为空','warning');
		return;
	}

	if(tel.length > 0){
		if(!(/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(tel))){ 
			showTip("手机号码有误，请重填",'warning');
			return false; 
		}
		if(tel != old_tel){
			if(checkMobile(tel)){
				showTip('该手机号码已存在','warning');
				return; 
			}
		}
	}
	 if(email.length > 0){
		if(!(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(email))){ 
			showTip('邮箱错误,请重填','warning');
			return false; 
		}
		if(email != old_email){
			if(checkEmail(email)){
				showTip('该邮箱已存在','warning');
				return; 
			}
		}
	}

	var user_data = {
		'uid':uid,
		'nick_name' : nickname,
		'level_name' : level_name,
		'member_label' : member_label,
		'tel' : tel,
		'email' : email,
		'sex' : sex,
		'status' : status
	};

	if($("#hidden_old_username").val() == ""){
		user_data.user_name = username;
	}

	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/member/updatemember')}",
		data : user_data,
		success : function(data) {
			if (data['code'] > 0) {
				showTip(data['message'],'success');
				LoadingInfo(getCurrentIndex(uid,'#productTbody'));
				$("#modify_user").modal("hide");
			} else {
				showTip(data['message'],'error');
				flag = false;
			}
		}
	});
}

//批量删除
function batchDelete() {
	var uid= [];
	$("#productTbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			uid.push($(this).val());
		}
	});
	if(uid.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#0059d6,#fff": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	delete_user(uid);
}

/**
 * 会员数据导出
 */
function dataExcel(){
	var search_text = $("#search_text").val();
	var levelid = $("#level_name").val();
	var label_id = $("#selectMemberLabelId").val();
	var start_date = $("#startDate").val();
	var end_date = $("#endDate").val();
	$.ajax({
		url : "{:__URL('ADMIN_MAIN/member/memberExcellist')}",
		type : "post",
		data : {
			"search_text" : search_text,
			"levelid" : levelid,
			"start_date" : start_date,
			"end_date" : end_date,
			"label_id" : label_id
		},
		success : function (data){
			if(data['data'] != ""){
				window.location.href=__URL("ADMIN_MAIN/member/memberDataExcel?search_text="+search_text+"&levelid="+levelid+"&start_date="+start_date+"&end_date="+end_date+"&label_id="+label_id);
			}else{
				showTip("没有导出的会员数据",'error');
			}
		}
	});
}

// 点击显示更多搜索
$(".more-search").on("click", function(e){
	$(".more-search-container").slideToggle();
	$(document).one("click", function(){
        $(".more-search-container").slideUp();
    });
    e.stopPropagation();
});

$(".more-search-container").on("click", function(e){
    e.stopPropagation();
});

function selectMemberLabel(){
	$("#selectMemberLabel").popover("show");
	$("#selectMemberLabelId").val('');
	$("#selectMemberLabel").val('');
}

function clickMemberLabel(event){
	var goods_label_id = $(event).val();
	var goods_label_name = $(event).next("span").text();
	var selectMemberLabelVal = $("#selectMemberLabel").val();
	var selectMemberLabelId = $("#selectMemberLabelId").val();
	if($(event).is(":checked")){
		$("#selectMemberLabelId").val(selectMemberLabelId+goods_label_id+',');
		$("#selectMemberLabel").val(selectMemberLabelVal+goods_label_name+';');
	}else{
		selectMemberLabelVal = selectMemberLabelVal.replace(goods_label_name+';','');
		selectMemberLabelId = selectMemberLabelId.replace(goods_label_id+',','');
		$("#selectMemberLabelId").val(selectMemberLabelId);
		$("#selectMemberLabel").val(selectMemberLabelVal);
	}
}

function hideGroup(){
	$("#selectMemberLabel").popover("hide");
	$("#selectMemberLabel").val('');
	$("#addSelectMemberLabel").popover("hide");
	$("#addSelectMemberLabel").val('');
}

function confirm(){
	$("#selectMemberLabel").popover("hide");
	$("#addSelectMemberLabel").popover("hide");
}

function addSelectMemberLabel(){
	$("#addSelectMemberLabel").popover("show");
	$("#addSelectMemberLabelId").val('');
	$("#addSelectMemberLabel").val('');
}

function addclickMemberLabel(event){
	var goods_label_id = $(event).val();
	var goods_label_name = $(event).next("span").text();
	var selectMemberLabelVal = $("#addSelectMemberLabel").val();
	var selectMemberLabelId = $("#addSelectMemberLabelId").val();
	if($(event).is(":checked")){
		$("#addSelectMemberLabelId").val(selectMemberLabelId+goods_label_id+',');
		$("#addSelectMemberLabel").val(selectMemberLabelVal+goods_label_name+';');
	}else{
		selectMemberLabelVal = selectMemberLabelVal.replace(goods_label_name+';','');
		selectMemberLabelId = selectMemberLabelId.replace(goods_label_id+',','');
		$("#addSelectMemberLabelId").val(selectMemberLabelId);
		$("#addSelectMemberLabel").val(selectMemberLabelVal);
	}
}

function saveMemberLabel() {
	var addSelectMemberLabel = $('#addSelectMemberLabelId').val();
	var uid = $('#modify_uid').val();
	$.ajax({
		url: "{:__URL('ADMIN_MAIN/member/updateMemberLabel')}",
		type: 'post',
		data: {'uid' : uid, 'member_label' : addSelectMemberLabel},
		success: function (data) {
			if (data["code"] > 0) {
				showTip(data['message'],'success');
				$("#modify_tab").modal("hide");
				LoadingInfo(1);
			}else{
				showTip(data['message'],'error');
			}
		}
	});
}

function closeMemberLabel() {
	$("#modify_tab").modal("hide");
	hideGroup();
}
</script>
{/block}